package com.example.mydataaccesssample;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ActShared extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.common);
		InitialComponent();
	}
	OnClickListener btnSave_click=new OnClickListener(){
		public void onClick(View arg0) {
			
			SharedPreferences table = getSharedPreferences("T1", 0);
			Editor editor=table.edit();
			editor.putString("KK", txtSave.getText().toString()).commit();
			
			Toast.makeText(ActShared.this, "儲存資料成功", Toast.LENGTH_SHORT).show();
	}};

	OnClickListener btnGet_click=new OnClickListener(){
		public void onClick(View arg0) {
			SharedPreferences table = getSharedPreferences("T1", 0);
			lblGet.setText(table.getString("KK","default text"));

	}};
	
	private void InitialComponent() {
		
		btnSave=(Button)findViewById(R.id.btnSave);
		btnSave.setOnClickListener(btnSave_click);
		
		btnGet=(Button)findViewById(R.id.btnGet);
		btnGet.setOnClickListener(btnGet_click);
		
		lblGet=(TextView)findViewById(R.id.lblGet);
		txtSave=(EditText)findViewById(R.id.txtSave);
	
	}
   
	Button btnSave=null;
	Button btnGet=null;
	TextView lblGet=null;
	EditText txtSave=null;


}
